using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class YH_StandingBookProcessService : BaseAppService<YH_StandingBookProcessDto, YH_StandingBookProcess , YH_StandingBookProcessRepository>
        {
        readonly ExcelHelp _excelHelp;
        public YH_StandingBookProcessService (YH_StandingBookProcessRepository repository,ExcelHelp excelHelp) : base(repository){
        _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<YH_StandingBookProcess, YH_StandingBookProcessDto>
            GetLoadPageOffsetMode(PagingModel<YH_StandingBookProcessDto>
                pagingQueryModel)
                {
                var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
                var baseQuery = _repository.QueryBase().AsNoTracking();
                loadPageOffsetModel.QueryWhere = this.CreateQRList()

         .Add("StandingBookId","=") //
         .Add("ProcessName","=") //
         .Add("ProcessDept","=") //
         .Add("ProcessUser","=") //
         .Add("ProcessDate","=") //
         .Add("ProcessResult","=") //
         .Add("ProcessContent","=") //
         .Add("NextName","=") //
         .Add("NextUser","=") ;//


                loadPageOffsetModel.BasqQuery = baseQuery;
                loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
                loadPageOffsetModel.Selector = model => new  YH_StandingBookProcess() {
                Id = model.Id,
StandingBookId= model.StandingBookId,//
ProcessName= model.ProcessName,//
ProcessDept= model.ProcessDept,//
ProcessUser= model.ProcessUser,//
ProcessDate= model.ProcessDate,//
ProcessResult= model.ProcessResult,//
ProcessContent= model.ProcessContent,//
NextName= model.NextName,//
NextUser= model.NextUser,//
                };
                return loadPageOffsetModel;
                }


                public async Task <IPageModel<YH_StandingBookProcessDto>> GetList(PagingModel<YH_StandingBookProcessDto>
                    pagingQueryModel)
                    {
                    var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                    return await base.LoadPageOffsetAsync(loadPageOffsetModel);
                    }


                    public async Task<string>
                        Export(PagingModel<YH_StandingBookProcessDto>
                            pagingQueryModel)
                            {
                            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
                            var excelData = DataList.Select(model => new
                            {
model.StandingBookId,
StandingBookId_title ="",
model.ProcessName,
ProcessName_title ="",
model.ProcessDept,
ProcessDept_title ="",
model.ProcessUser,
ProcessUser_title ="",
model.ProcessDate,
ProcessDate_title ="",
model.ProcessResult,
ProcessResult_title ="",
model.ProcessContent,
ProcessContent_title ="",
model.NextName,
NextName_title ="",
model.NextUser,
NextUser_title ="",
                            }).ToList();




                            return _excelHelp.Create(excelData);
                            }

                            }

                            }
